package com.fenghuajueli.libbasecoreui.ui;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperTextView;
import com.blankj.utilcode.util.AppUtils;
import com.fenghuajueli.libbasecoreui.R;
import com.fenghuajueli.libbasecoreui.mvp.BaseActivity;
import com.fenghuajueli.libbasecoreui.utils.MmkvUtils;
import com.fenghuajueli.libbasecoreui.utils.PrivacyConstantsUtils;

public class AboutUsActivity extends BaseActivity {

    private ImageView icon;
    private TextView appName;
    private TextView appVersion;
    private SuperTextView stPrivacy;
    private SuperTextView stRecommend;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);
        icon = findViewById(R.id.icon);
        appName = findViewById(R.id.appName);
        appVersion = findViewById(R.id.appVersion);
        stPrivacy = findViewById(R.id.stPrivacy);
        stRecommend = findViewById(R.id.stRecommend);
        stPrivacy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PrivacyWebActivity.start(AboutUsActivity.this, PrivacyConstantsUtils.ProtocolType.PRIVACY);
            }
        });
        try {
            PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            appVersion.setText(packageInfo.versionName);
            Drawable iconDrawable = AppUtils.getAppIcon();
            if (iconDrawable != null) {
                icon.setImageDrawable(iconDrawable);
            }
            String name = AppUtils.getAppName();
            if (!TextUtils.isEmpty(name)) {
                appName.setText(name);
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        stRecommend.setSwitchIsChecked(MmkvUtils.get("tuijian",true));
        stRecommend.setSwitchCheckedChangeListener(new SuperTextView.OnSwitchCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                MmkvUtils.save("tuijian",isChecked);
                if (!isChecked) {
                    showToast("已关闭！");
                }
            }
        });

    }
}
